// pages/my/teacher/exercise/exercise.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    winWidth:0,
    winHeight:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        console.log(res);
        that.setData({ winWidth:res.windowWidth});
        that.setData({ winHeight: res.windowHeight });
      },
    })

    wx.getStorage({
      key: 'teacher_id',
      success: function (res) {
        wx.request({
          url: base_url+'/getAllexercise/',
          method: 'POST',
          data: {
            teacher_id: res.data
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if (res.data['flag'] == true) {
              console.log(res.data)
              that.setData({
                classDatas_lst: res.data['classDatas_lst'],
                exerciseDatas_lst: res.data['exerciseDatas_lst']
              })
              console.log(that.data.exerciseDatas_lst)
            }else{
              wx.redirectTo({
                url: '../noclass/noclass',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }
          }
        })


      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  switchNav:function(e){
    var page = this;
    if(this.data.currentTab == e.target.dataset.current){
      console.log(e.target.dataset.current)
      return false;
    }else{
      page.setData({currentTab:e.target.dataset.current})
      console.log(e.target.dataset.current)
    }
  },
  setExercise:function(){
    wx.navigateTo({
      url: '../setExercise/setExercise',
      success: function (res) {
        console.log(res)
      },
      fail: function () {
      }
    })
  },
  getThisExercise:function(res){
    console.log(res.currentTarget.dataset.name)
    var strs = new Array(); //定义一数组
    var id = res.currentTarget.dataset.name
    console.log(id)
    strs = id.split(",");
    wx.request({
      url: base_url+'/getThisexercise/',
      method: 'POST',
      data: {
        shid: strs[0],
        cid: strs[1]
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data['flag'] == true) {
          console.log(res.data)
          wx.setStorage({
            key: 'ccount',
            data: res.data['ccount'],
          })
          wx.setStorage({
            key: 'nocount',
            data: res.data['nocount'],
          })
          wx.setStorage({
            key: 'allExerciseList',
            data: res.data['lst'],
            success: function (res) {
              wx.navigateTo({
                url: '../exerciselist/exerciselist',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }
          })
        }
      }
    })
    
  }
})